package algo3c3g3.view;

import javax.swing.*;
import java.awt.*;
import java.util.*;
import algo3c3g3.model.*;

/**
 * Muestra infirmacion sobre el estado del juego.
 */
public class StatusPanel extends JPanel implements Observer
{
    private Level level;
    private World world;
    
    private JLabel
        out, saved, lost, time;
    
    private static final int HGAP = 30;
    
    
    /**
     * @param level Modelo de datos asociado.
     */
    public StatusPanel(Level level)
    {
        this.level = level;
        world  = level.getWorld();
        
        FlowLayout layout = new FlowLayout();
        layout.setHgap(HGAP);
        setLayout(layout);
        
        add(new JLabel("Total: " + level.getMaxUnitQty()));
        add(new JLabel("A Salvar: " + level.getUnitQtyToSave()));
        
        out = new JLabel("Afuera: " + world.getUnitQty());
        add(out);
        
        saved = new JLabel("Salvadas: " + world.savedUnits());
        add(saved);
        
        lost = new JLabel("Perdidias: " + world.killedUnits());
        add(lost);
        
        add(new JLabel("Tiempo total: " + level.getTiemOut()));
        
        time = new JLabel("Tiempo: " + level.getTime());
        add(time);
        
        world.addObserver(this);
    }
    
    public void update(Observable o, Object arg)
    {
        out.setText("Afuera: " + world.getUnitQty());
        saved.setText("Salvadas: " + world.savedUnits());
        lost.setText("Perdidias: " + world.killedUnits());
    }
    
    /**
     * Muestra el tiempo del juego.
     */
    public void updateTime()
    {
        time.setText("Tiempo: " + level.getTime());
    }
}
